package com.example.miaoshasoft.controller;

import com.example.miaoshasoft.domain.Student;
import com.example.miaoshasoft.json.Json;
import com.example.miaoshasoft.service.StudentsService;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("users")
public class StudentsController extends BaseController{

    @Resource
    private StudentsService studentsService;

    @GetMapping("delete")
    public void StudentDe(int sid){

        studentsService.deleteById(sid);

    }
    @GetMapping("searchAll")
    public Map<String,Object> StudentsSearch(){

        try {
            List<Student> studentList = studentsService.findAll();
            return Json.success(studentList);
        } catch (Exception e) {
            return Json.fail();
        }

    }
    @GetMapping("search")
    public Map<String, Object> StudentSearchById(int sid){
        try {
            Student s = studentsService.getOne(sid);
            System.out.println(s);
            return Json.success(s);
        } catch (Exception e) {
            return Json.fail("shibai");
        }
    }

}
